using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;

using ROC.Resources.Library.Data.SQL2005;

namespace MoneyManagerPro.Resources.Repository.Users
{
    internal class UserUpdateFactory : IUpdateFactory<MoneyManagerPro.Business.Entities.User>
    {
        public UserUpdateFactory()
        {
        }

        #region IUpdateFactory<User> Members

        public SqlCommand ConstructUpdateCommand(SqlDatabase db, MoneyManagerPro.Business.Entities.User user)
        {
            SqlCommand command = db.GetStoredProcCommand("UpdateUser");

            db.AddInParameter(command, "Id", SqlDbType.Int, user.Id);
            db.AddInParameter(command, "FirstName", SqlDbType.NVarChar, user.FirstName);
            db.AddInParameter(command, "LastName", SqlDbType.NVarChar, user.LastName);
            db.AddInParameter(command, "UserName", SqlDbType.NVarChar, user.UserName);
            db.AddInParameter(command, "Password", SqlDbType.NVarChar, user.Password);
            db.AddInParameter(command, "Email", SqlDbType.NVarChar, user.Email);
            db.AddInParameter(command, "LastVisit", SqlDbType.DateTime, user.LastVisit);
            db.AddInParameter(command, "Description", SqlDbType.NVarChar, user.Description);

            return command;
        }

        #endregion

        #region IDbToBusinessEntityNameMapper Members

        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
                case "Id":
                case "FirstName":
                case "LastName":
                case "UserName":
                case "Password":
                case "Email":
                case "LastVisit":
                case "Description":
                    return dbParameter;
                default:
                    throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, ROC.Resources.Library.Data.Generic.GenericResources.InvalidParameterName), dbParameter);
            }
        }

        #endregion
    }
}
